﻿using System;
using Microsoft.EntityFrameworkCore;
using DataLibrary.Entity;

namespace DataLibrary
{
    public class UpgradeDbContext : DbContext
    {
        public UpgradeDbContext(DbContextOptions options) : base(options) { }

        public DbSet<Account> Accounts { get; set; }
        public DbSet<FileMagic> FileMagics { get; set; }
        public DbSet<Product> Products { get; set; }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity<Account>()
                .HasMany(x => x.Products)
                .WithOne(x => x.Account)
                .HasForeignKey(x => x.AccountId);

            builder.Entity<Product>()
                .HasMany(x => x.FileMagics)
                .WithOne(x => x.Product)
                .HasForeignKey(x => x.ProductId);
        }
    }
}
